package com.md.youyouhui.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.md.youyouhui.R;
import com.md.youyouhui.databinding.AdapterHomePayBinding;
import com.md.youyouhui.net.response.GetHomeMealNewResponse;
import com.md.youyouhui.ui.fragment.PayOilActivity;

import java.util.List;

/**
 * Created by AdministratorZJ
 * on 2019/4/8.
 */
public class HomeMealAdapter extends RecyclerView.Adapter<DataBoundViewHolder<AdapterHomePayBinding>> {
    private Context context;
    private List<GetHomeMealNewResponse> rows;

    public HomeMealAdapter(Context context) {
        this.context = context;
    }

    public void upDate(List<GetHomeMealNewResponse> rows) {
        this.rows = rows;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public DataBoundViewHolder<AdapterHomePayBinding> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        AdapterHomePayBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.adapter_home_pay, viewGroup, false);
        return new DataBoundViewHolder<>(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull DataBoundViewHolder<AdapterHomePayBinding> holder, int i) {
        holder.binding.homeMonth.setText(rows.get(i).months);
        holder.binding.homeMonthPrice.setText(rows.get(i).monthly);
        holder.binding.homeAllPrice.setText("套餐价:"+rows.get(i).discountedPrice);
        holder.binding.homeSavePrice.setText(rows.get(i).discount);
        holder.itemView.setOnClickListener(v -> context.startActivity(new Intent(context, PayOilActivity.class)
                .putExtra("mealId", rows.get(i).id).putExtra("price", rows.get(i).monthSspread)));
    }

    @Override
    public int getItemCount() {
        return null == rows ? 0 : rows.size();
    }


}
